﻿// myRequest表示XMLHttpRequest对象，selectId表示<select>标签的id属性值
	function onReadyState(myRequest, selectId) 
	{ 
		if(myRequest.readyState == 4)   // 4表示成功获得相应信息 
		{              
			try
			{
				
				var xml = myRequest.responseText;   // 获得XMLDocument对象     
				var kind = document.getElementById(selectId); // 获得<select>对象
				kind.innerHTML = xml;
				//addOptions(kind, xml);  // 向<select>标签中加入<option>标签
			}
			catch(e)
			{
				alert("onReadyState:" + e);
			}
		}
	}
	//
	/*创建XMLHttpRequest对象*/
	function createRequest()
	{
		if(typeof XMLHttpRequest!="undefined")
		{
			return new XMLHttpRequest();
		}
		else if(typeof ActiveXObject!="undefined")
		{
			var xmlHttp_ver = false;
			var xmlHttp_vers = [
				"MSXML2.XmlHttp.5.0",
				"MSXML2.XmlHttp.4.0",
				"MSXML2.XmlHttp.3.0",
				"MSXML2.XmlHttp",
				"Microsoft.XmlHttp"
				];
			if(!xmlHttp_ver)
			{
				for(var i=0;i<xmlHttp_vers.length;i++)
				{
					try{
							new ActiveXObject(xmlHttp_vers[i]);
							xmlHttp_ver = xmlHttp_vers[i];
							break;
						}
					catch(oError){;}
				}
			}
		}
		if(xmlHttp_ver)
		{
			return new ActiveXObject(xmlHttp_ver);
		}
		else
		{
			throw new Error("您的浏览器不支持 XMLHTTP 请求.");
		}
	}
	//
	function getData(url, selectId)
	{
		
		var myRequest = createRequest();  // 获得一个XMLHttpRequest对象
		var kind = document.getElementById(selectId); // 获得<select>对象
		kind.innerHTML = '';
		kind.innerHTML = "<img src='../images/loading.gif' widht='16px' height='16px' />";
		if(myRequest)
		{
			myRequest.onreadystatechange =  function() // 接收获得数据状态的事件函数
			{        
				              
				onReadyState(myRequest, selectId);  
			}
			 
			try 
			{
				myRequest.open( "post", url, true);
			}
			catch(e)
			{
				alert(e);
			} 
			try
			{
				myRequest.send("");
			}
			catch(e)
			{
				alert(e);
			}
	  
		}
	}